/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ModelLayer;

import CustomExceptions.OutOfStockException;

/**
 *
 * @author Claus
 */
public class SalesLineItem
{
	int sliID;
	int quantity;
	Product prod;
	SalesOrder order;

	public SalesLineItem()
	{
		this.quantity = 0;
		this.prod = null;
	}

	public SalesLineItem(int quantity, Product saleItem)
	{
		this.quantity = quantity;
		this.prod = saleItem;
	}

	public boolean addItems(int num)
	{
		try
		{
			prod.decreaseStock(num);
			quantity += num;
			return true;
		}
		catch(OutOfStockException e)
		{
			return false;
		}
	}

	public void removeItems(int num)
	{
		if(num > quantity)
		{
			removeAllItems();
		}
		else
		{
			prod.increaseStock(num);
			quantity -= num;
		}
	}

	public void removeAllItems()
	{
		prod.increaseStock(quantity);
		quantity -= quantity;
	}

	public float getPrice()
	{
		float price = prod.getSalesPrice() * quantity;

		return price;
	}

	public int getQuantity()
	{
		return quantity;
	}

	public void setQuantity(int quantity)
	{
		this.quantity = quantity;
	}

	public Product getProduct()
	{
		return prod;
	}

	public void setProduct(Product saleItem)
	{
		this.prod = saleItem;
	}

	public int getSliID()
	{
		return sliID;
	}

	public void setSliID(int sliID)
	{
		this.sliID = sliID;
	}

	public SalesOrder getOrder()
	{
		return order;
	}

	public void setOrder(SalesOrder order)
	{
		this.order = order;
	}
}
